import numpy as np
from scipy import stats
from multiprocessing import Pool
from obspy import read
from scipy.signal import spectrogram
import matplotlib.pyplot as plt

def print1(str):
    print(str)

if __name__ == '__main__':
    # nums = [1, 2.2, 3, 2, 3.0, 2, 3, 45, 6, 7, 4, 4, 3, 2, 3, 1]
    #
    # print(np.mean(nums))
    # print(np.median(nums))
    # print(stats.mode(nums)[0][0])
    # counts = np.bincount(nums)
    # n = np.argmax(counts)
    # print(n)
    #
    #
    # nums = [1, 1, 2, 2, 4, 6, 9]
    # print(np.median(nums))
    # me = np.median(nums)
    # print(me)
    # n = np.median(np.abs(nums-me))
    # print(n)
    # s = -1
    # print(np.abs(s))
    #
    #
    # pool = Pool(1)
    # str = 'wooooooo'
    # pool.map(print1,str)

    files = '../data/Deci5.Pick.19991015130000.CI.CDY.EHZ.sac'
    st = read (files)
    print(st)

    data = st[0].data
    print(data)
    f, t, Sxx = spectrogram(data, fs=20, window='hanning',
                            nperseg=int(20 * 6.0),
                            noverlap=int(20 * (6.0 - 0.2)))

    nf,nt = np.shape(Sxx)
    print(nf)
    print(nt)
    # print(t)
    # print(Sxx)

    N = 61
    L = 32
    dL = 5
    idx0 = np.asarray(range(0, N + 1, dL))
    idx2 = np.asarray(range(L, N + 1, dL))
    nWindows = len(idx2)
    idx1 = idx0[0:nWindows]
    print(idx0)
    print(idx1)
    print(idx2)
    print(nWindows)
